#include "StdAfx.h"
#include "SpriteCanvas.h"
#include "EffectSprite.h"

CEffectSprite::CEffectSprite(void)
{
	m_nImageFrameCount = 0;
}

CEffectSprite::~CEffectSprite(void)
{
}


void CEffectSprite::Play(CxImage *pSpriteImage, int nImageFrameCount, CPoint ptSrc, CPoint ptDst,  int nTotalFrame, int nIntervalTime, CSpriteCanvas* pContainer)
{
	m_pSpriteImage = pSpriteImage;
	if(m_pSpriteImage->IsValid())
	{
		m_nImageFrameCount = nImageFrameCount;
		int nWidth = pSpriteImage->GetWidth() / m_nImageFrameCount;
		int nHeight = pSpriteImage->GetHeight();
        SetRect(CRect(ptSrc.x, ptSrc.y, ptSrc.x + nWidth, ptSrc.y + nHeight));
		PlayMove(ptDst.x, ptDst.y, nTotalFrame, nIntervalTime);
		pContainer->AddSprite(this);
	}
}

void CEffectSprite::Render(CDC *pDC)
{
	if(m_pSpriteImage->IsValid())
	{
		int nWidth = GetWidth();
		int nHeight = GetHeight();
		int nFrameIndex = m_nCurFrame % m_nImageFrameCount;
		CRect rcSrc(nFrameIndex * nWidth, 0, nFrameIndex * nWidth + nWidth, nHeight);
		m_pSpriteImage->DrawPart(pDC->m_hDC, GetRect(), rcSrc);
	}
}

